////////////////////////////////////////////////
// DESCRIPTION:
//    Installable ISR API
//
// Legal Notices:
//     Copyright (c) 2008, Telliam Consulting, LLC.
//     All rights reserved.
//
//     Redistribution and use in source and binary forms, with or without modification,
//     are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright notice,
//       this list of conditions and the following disclaimer in the documentation
//       and/or other materials provided with the distribution.
//
//     * Neither the name of Telliam Consulting nor the names of its contributors
//       may be used to endorse or promote products derived from this software
//       without specific prior written permission.
//
// Disclaimer:
//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
//     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
//     OF THE POSSIBILITY OF SUCH DAMAGE.  
//

#pragma once

#if _WIN32_WCE > 0x600 
#error FusionWare::DFX::IISRAPI Not tested nor supported on Windows CE versions greater than V6.00 
#endif

namespace FusionWare
{
    namespace DFX
    {
        namespace IISRAPI
        {
            // {internal}
            // CELOG import table uses a radically different structure in Macallan.
            // Fortunately the kernel still supports older logger DLLs using the CELOG
            // support so mark the version needed for access to the Win32 APIs
            //
            const int CELOG_IMPORT_VERSION = 2;
            
            // {secret}
            typedef void (*FUNCPTR)();
            
            // {secret}
            typedef int (*IntsEnablePtr)(int Enable);

            // {secret}
            // Provided by the kernel for celog to use
            struct CeLogImportTableV2
            {
                unsigned long    dwVersion;       // Version of this structure, set to CELOG_IMPORT_VERSION
                const FUNCPTR *pWin32Methods;     // Kernel Win32 (non-handle-based) methods
                const FUNCPTR *pEventMethods;     // Handle-based event methods
                const FUNCPTR *pMapMethods;       // Handle-based memory-mapped file methods
                IntsEnablePtr  INTS_ENABLE;       // Pointer to INTERRUPTS_ENABLE function
                FUNCPTR  Phys2Virt;               // Pointer to Phys2Virt function
                FUNCPTR  InSysCall;               // Pointer to InSysCall function
                FUNCPTR  KCall;                   // Pointer to KCall function
                FUNCPTR  NKDbgPrintfW;            // Pointer to NKDbgPrintfW function
                void    *pKData;                  // Pointer to KData struct
                unsigned long *pdwCeLogTLBMiss;   // Pointer to TLB miss count
                unsigned long  dwCeLogLargeBuf;         // OEM-changeable large buffer size
                unsigned long  dwCeLogSmallBuf;         // OEM-changeable small buffer size
                unsigned long  dwDefaultThreadQuantum;  // The scheduler's default thread quantum
            };

            // {internal}
            // Inputs from kernel
            extern CeLogImportTableV2 g_Imports;
        }
    }
}

//------------------------------------------------------------------------------
// override standard Call macro.
// {secret}
#define WINCEMACRO 1
//{secret}
#define WIN32_CALL(type, api, args) ( (*(type (*)args)(FusionWare::DFX::IISRAPI::g_Imports.pWin32Methods[W32_ ## api])) )

#include <Windows.h>
#include <nkintr.h>
#include <FusionWare\Crt.h>

// override INTERRUPTS_ENABLE with a macro too 
//{secret}
#define INTERRUPTS_ENABLE FusionWare::DFX::IISRAPI::g_Imports.INTS_ENABLE

